package com.wanxi.servlet;

import com.wanxi.model.BrandModel;
import com.wanxi.service.BrandService;
import com.wanxi.utils.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Li
 * @Date 2023/4/26 10:43
 */
@WebServlet("/findById")
public class BrandFindByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        乱码处理
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        拿到前端的值
        String id = req.getParameter("id");
        //封装model
        BrandModel brandModel =  BrandModel.builder()
                .id(Tool.strToInt(id))
                .build();
//        调用服务逻辑层
        BrandService brandService = new BrandService();
       BrandModel model = brandService.findById(brandModel);
       //返回model数据给前端
        req.setAttribute("model",model);
        req.getRequestDispatcher("/BrandUpdate.jsp").forward(req,resp);
    }
}
